package com.pet.mapper;

import com.pet.entity.PetAdoptApplication;
import com.pet.entity.PetHealthInformation;
import com.pet.entity.PetHelpInformation;
import com.pet.entity.PetHelpRemark;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PetHelpInformationMapper {


    @Select("select  pet_help_information.*, user_information.name AS name ,user_information.id as createUserId " +
            "from user_information,pet_help_information " +
            "where user_information.id = pet_help_information.create_user")
    List<PetHelpInformation> selectPetHelpInformation();


    /**
     * 添加动物求助信息
     * @param entity
     */
    @Insert("insert into pet_manage_system.pet_help_information " +
            "(pet_name, pet_type, gender, age, pet_img, " +
            "vaccine, insect_repellent, sterilization, pet_introduce, public_area, " +
            "create_user, create_time, update_user, update_time, help_type, help_detail,phone,wechat) " +
            "VALUES " +
            "(#{petName}, #{petType}, #{gender}, #{age}, #{petImg}, " +
            "#{vaccine}, #{insectRepellent}, #{sterilization}, #{petIntroduce}, #{publicArea}, " +
            "#{createUser}, #{createTime}, #{updateUser}, #{updateTime}, #{helpType}, #{helpDetail},#{phone},#{wechat})")
    void insertPetHelpInformation(PetHelpInformation entity);

    /**
     * 评论
     * @param entity
     */
    @Insert("insert into pet_help_remark" +
            "(remark, create_time, create_user, help_id)" +
            "values " +
            "(#{remark},#{createTime},#{createUser},#{helpId})")
    void insertPetHelpRemark(PetHelpRemark entity);

    @Select("select * from pet_help_remark where help_id =#{helpId}")
    List<PetHelpRemark> selectPetHelpRemark(Integer helpId);

    @Select("select * from pet_help_information where create_user = #{currentId}")
    List<PetHelpInformation> selectPetHelpInfosBySelfId(Integer currentId);

    @Delete("delete from pet_help_information where id=#{id}")
    void deletePetHelpInformation(Long id);

    @Select("select * from pet_adopt_info where id = #{id}")
    PetHelpInformation selectPetHelpInfoById(Long id);

    @Delete("delete from pet_help_remark where help_id = #{id}")
    void deletePetHelpRemarkByHelpId(Long id);

    /**
     *修改个人帖子
     * @param petHelpInformation
     */
    void updatePetHelpInformation(PetHelpInformation petHelpInformation);

    @Delete("delete from pet_help_information where create_user = #{userId}")
    void deletePetHelpInformationByUserId(Integer userId);
}
